<!DOCTYPE html>
<html lang='en'>

<head>
    <meta charset='UTF-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Document</title>
    <script src='../node_modules/react/umd/react.development.js'></script>
    <script src='../node_modules/react-dom/umd/react-dom.development.js'></script>
    <script src='../node_modules/babel-standalone/babel.min.js'></script>
    <script src='../node_modules/prop-types/prop-types.js'></script>
</head>

<body>
    <div id='root'></div>
    <script type='text/babel'>
        class MyCom extends React.Component {
            constructor(props) {
                super(props)

                this.state = {
                    userInput: "你妹",
                }
            }

            clickHandler = () => {
                console.log(this.refs.ref1.value);
            }

            /* 用户输入什么state.userInput就是什么 */
            onUserInputChange = (e) => {
                this.setState({
                    userInput: e.target.value
                })
            }

            render() {
                return (
                    <div>
                       
                        <div>{this.state.userInput}</div>
                        
                        <input type="text" ref="ref1"
                            value={this.state.userInput}
                            onChange={this.onUserInputChange}
                        />

                        <button onClick={() => {
                            console.log("userInput=", this.state.userInput);
                            this.setState({
                                userInput: new Date().toString()
                            })
                        }}>修改state</button>

                    </div>
                )
            }

        }
        ReactDOM.render(<MyCom />, document.getElementById('root'))
    </script>
</body>

</html>